//
// Created by zuo on 2024/7/4.
// 题目链接  https://www.lanqiao.cn/problems/498/learning/?page=1&first_category_id=1&problem_id=498
//

#include<bits/stdc++.h>
using namespace std;

// string -> int
int s2i(string s)
{
    int res = 0;
    for (const auto& i : s) res = res * 10 + i - '0';
    return res;
}

// int -> string
string i2s(int x, int w)
{
    string res;
    while (x)
    {
        res += (x % 10) + '0';
        x /= 10;
    }
    while (res.length() < w) res += '0';
    reverse(res.begin(), res.end());
    return res;
}

// 判断闰年
bool isLeapYear(int year)
{
    return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}

// 判断日期是否合法
bool isOk(int year, int month, int day)
{
    int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 数组下标对应月份的天数
    if (isLeapYear(year)) days[2] = 29; // 闰年29天
    return day <= days[month];
}

bool huiwen(string s)
{
    int l = s.length() / 2;
    for (int i = 0; i < l; i++)
    {
        if (s[i] != s[s.length() - 1 - i]) return false;
    }
    return true;
}

bool ABABBABA(string s)
{
    if (!huiwen(s)) return false; // 不是回文数 一定不是 ABABBABA
    return s[0] == s[2] && s[1] == s[3]; // 回文的基础上 加上AB相等的条件
}

int main()
{
    string N;
    cin >> N;
    int year = s2i(N.substr(0, 4));
    int month = s2i(N.substr(4, 2));
    int day = s2i(N.substr(6, 2));
    bool ans1 = false, ans2 = false;
    for (int i = year; i <= 9999; i++)
    {
        for (int j = 1; j <= 12; j++)
        {
            if (i == year && j < month) continue;
            for (int k = 1; k <= 31; k++)
            {
                // <= 因为是下一个回文日期 所以本次的不算
                if (i == year && j == month && k <= day) continue;

                // 当前日期及以后日期的计算
                if (!isOk(i, j, k)) continue;
                string date = i2s(i, 4) + i2s(j, 2) + i2s(k, 2);
                if (!ans1 && huiwen(date))
                {
                    cout << date << '\n';
                    ans1 = true;
                }
                if (!ans2 && ABABBABA(date))
                {
                    cout << date << '\n';
                    ans2 = true;
                }
            }
        }
    }

    return 0;
}
